package main

import (
	"bufio"
	"os"
	"strings"
)

// func main() {
// 	client := NewRedisClient()

// 	var wg sync.WaitGroup

// 	// 启动生产者
// 	wg.Add(1)
// 	go Producer(client, QueueName, &wg)

// 	// 启动多个消费者
// 	for i := 0; i < ConsumerCount; i++ {
// 		wg.Add(1)
// 		go Consumer(client, QueueName, &wg)
// 	}

// 	fmt.Println("Message queue started. Press Ctrl+C to exit.")
// 	wg.Wait()
// }

// func main() {
// 	client := NewRedisClient()

// 	var wg sync.WaitGroup

// 	// 启动日志生成器
// 	wg.Add(1)
// 	go Logger(client, QueueName, &wg)

// 	// 启动日志处理器
// 	wg.Add(1)
// 	go LogProcessor(client, QueueName, &wg)

// 	fmt.Println("Log processing system started. Press Ctrl+C to exit.")
// 	wg.Wait()
// }

// Logger function to simulate log generation
// func Logger(client *RedisClient, queueName string, wg *sync.WaitGroup) {
// 	defer wg.Done()
// 	// Simulate log generation
// }

// // LogProcessor function to process logs
// func LogProcessor(client *RedisClient, queueName string, wg *sync.WaitGroup) {
// 	defer wg.Done()
// 	// Simulate log processing
// }

// Function to read logcat logs
func ReadLogcatLogs() ([]string, error) {
	file, err := os.Open("logcat.log") // Assuming logcat logs are saved in logcat.log
	if err != nil {
		return nil, err
	}
	defer file.Close()

	var logs []string
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		logs = append(logs, scanner.Text())
	}

	if err := scanner.Err(); err != nil {
		return nil, err
	}

	return logs, nil
}

// Function to filter logs for package mime and error level
func FilterLogs(logs []string) []string {
	var filteredLogs []string
	for _, log := range logs {
		if strings.Contains(log, "package mime") && strings.Contains(log, "E/") && strings.Contains(log, "FATAL EXCEPTION") {
			filteredLogs = append(filteredLogs, log)
		}
	}
	return filteredLogs
}
